﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Text;

namespace B10.Helpers
{
    public static class AdsenseHelperExtensions
    {
        static readonly string _adsenseId = "pub-6535843675780404";

        private static string Adsense(this HtmlHelper htmlHelper, string clientId, string slot, int width, int height)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("<div>");
            sb.AppendFormat(@"<script language=""javascript"" type=""text/javascript"">");
            if (String.IsNullOrEmpty(clientId))
                sb.AppendFormat("google_ad_client = \"{0}\";", _adsenseId);
            else
                sb.AppendFormat("google_ad_client = \"{0}\";", clientId);
            if (!String.IsNullOrEmpty(slot))
                sb.AppendFormat("google_ad_slot = \"{0}\";", slot);
            sb.AppendFormat("google_ad_width = {0};", width);
            sb.AppendFormat("google_ad_height = {0};", height);
            sb.AppendFormat("</script>");
            sb.AppendFormat(@"<script type=""text/javascript"" src=""http://pagead2.googlesyndication.com/pagead/show_ads.js"">
                    </script>");
            sb.AppendFormat("</div>");
            return sb.ToString();
        }

        public static string Adsense(this HtmlHelper htmlHelper)
        {
            return htmlHelper.Adsense(_adsenseId);
        }

        public static string Adsense(this HtmlHelper htmlHelper, string clientId)
        {
            return htmlHelper.Adsense(clientId, "", 468, 60);
        }

        public static string AdsenseRight(this HtmlHelper htmlHelper)
        {
            return htmlHelper.AdsenseRight(_adsenseId);
        }

        public static string AdsenseRight(this HtmlHelper htmlHelper, string clientId)
        {
            return htmlHelper.Adsense(clientId, "", 300, 250);
        }

        public static string AdsenseTop(this HtmlHelper htmlHelper)
        {
            return htmlHelper.Adsense(_adsenseId, "", 728, 90);
        }



        public static MvcForm BeginUploadForm(this HtmlHelper htmlHelper)
        {
            return htmlHelper.BeginForm(null, null, FormMethod.Post, new Dictionary<string, object> { { "enctype", "multipart/form-data" } });
        }

        public static string GetStatusName(this HtmlHelper helper, object intValue)
        {
            int value = (int)intValue;//Int32.Parse(intValue);
            B10.Models.PageStatus status = (B10.Models.PageStatus)value;
            switch (status)
            {
                case B10.Models.PageStatus.Accepted: return "Czeka na akceptację";
                case B10.Models.PageStatus.Created: return "Nie opublikowana";
                case B10.Models.PageStatus.Deny: return "Odrzucona";
                case B10.Models.PageStatus.Published: return "Zaakceptowana";
            }
            return "";
        }
    }
}
